package com.example.springboot0507.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author 王博
 * @DateTime 2025-05-09 13:24
 */
@Slf4j
@Component
@Aspect
public class MyAspect {

    @Pointcut("execution(* com.example.springboot0507.service.FirstService.sayHello(..))")
    public void pointCut(){}


    @Before("pointCut() && args(name)")
    public void before(JoinPoint point, String name) {
        Object[] args = point.getArgs();
        System.out.println(point);
        System.out.println(name);
        System.out.println("before");
    }

    @Around("pointCut() && args(name)")
    public Object around(ProceedingJoinPoint point, String name) throws Throwable {
        Object[] args = point.getArgs();

        log.info("arround");
        return point.proceed();
    }

    @AfterReturning("pointCut()")
    public void afterReturning() {
        System.out.println("afterReturning");
    }

    @AfterThrowing("pointCut()")
    public void afterThrowing() {
        System.out.println("afterThrowing");
    }

    @After("pointCut()")
    public void after() {
        System.out.println("after");
    }
}
